<%@page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@taglib uri="TowkerTagLib" prefix="rbac"%>
<%@include file="/commons/include/html_doctype.html"%>
<html>
<head>
	<title>添加</title>
	<%@include file="/commons/include/add.jsp" %>
	<script type="text/javascript" src="${ctx}/js/calendar/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript" src="${ctx}/js/calendar/date.js"></script>
	<script type="text/javascript">
$(function(){
	
	jQuery("#dataForm").validate(
	{
		rules: {
			in_type:{
				required:true
			},
			in_date:{
				required:true
			},
			depot_code:{
				required:true
			},
			dep_code:{
				required:true
			}
		},
		messages: {
			in_type:{
				required:"请选择入仓性质"
			},
			in_date:{
				required:"请选择入库日期"
			},
			depot_code:{
				required:"请选择仓库代码"
			},
			dep_code:{
				required:"请选择入仓部门代码"
			}
		},
		submitHandler:function(form)
		{
			setGoodsInfo();
			jQuery(form).ajaxSubmit(_options);
		}
	});
	selectDateMonth($("#acc_period_panel"), $("#acc_period"));
});
_callback = function() {
	location.href = ctx + "/manage/warehouse/getInWarehouse.htm";
}
validCallBack = function()
{
	//添加页面自定义校验
	if($("#goodsInfo").val() == "") {
		alert("请选择产品!");
		return false;
	}
	return true;
};

function setGoodsInfo() {
	var goodsInfoStr = "";
	//添加页面自定义校验
	for(var id in goods) {
		goodsInfoStr += id + ",";
	}
	//alert(goodsInfoStr);
	$("#goodsInfo").attr("value", goodsInfoStr);
}
var goods = {};
//JavaScript Document
function selectGoods() {
	//showModelessDialog
	//encodeURI、encodeURIComponent
	var source = encodeURIComponent(ctx+"/manage/basicData/selectGoods.htm?typeid=&classId=&r=" + Math.random());
	var url = ctx + "/commons/showDialog.jsp?r=" + Math.random() + "&url=" + source;
	var result = window.showModalDialog(url, this, "dialogWidth=600px;dialogHeight=600px;scroll=no");
	var panel = $("#MGoodsPanel");
	var html = "";
	for(var i = 0; i < result.length; i++) {
		var v = result[i];
		if(typeof(goods[v.id]) == "undefined" || goods[v.id] == null) {
			goods[v.id] = v.sn;
			html += '    <tbody><tr>'
				+ '      <td>' + v.sn + '<input type="hidden" name="wprice_' + v.id + '" id="wprice_' + v.id + '" value="' + v.wprice + '"  /></td>'
				+ '      <td>' + v.name + '</td>'
				+ '      <td><input name="amount_' + v.id + '" type="text" id="amount_' + v.id + '" value="0" size="10"   /></td>';
			if(1 == 2) {
				html += '<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>';
			} else {
				
			}
				html += '      <td>' + v.weight + '</td>'
				+ '      <td>' + v.unit + '</td>'
				+ '      <td><a href="#" onClick="deleteGoods(this, ' + v.id + ')">删除</a></td>'
				+ '    </tr>';
		}
	}
	html = html+'</tbody>';
	panel.append(html);
}
function deleteGoods(el, id) {
	var row = $(el).parent().parent();
	row.remove();
	goods[id] = null;
	delete goods[id];
}
	</script>
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0" class="listLogo">
	<tr>
		<td class="title">入仓单添加</td>
		<td>
			<div class="menuTool">
				<a class="save" id="dataFormSave" href="#">保存</a>
				<a class="back" href="getInWarehouse.htm">返回</a>
			</div>
		</td>
	</tr>
</table>
<div class="line"></div>
<form id="dataForm" method="post" action="addInWarehouse2.htm">
<input type="hidden" name="goodsInfo" id="goodsInfo" value="" />
<table border="0" cellspacing="1" cellpadding="0" class="listTable">
	<tr>
		<td class="form_title">入仓单号：</td>
		<td class="form_input"><input type="text" id="in_warehouse_code" readonly name="in_warehouse_code" value="${in_warehouse_code}" /></td>
	
		<td class="form_title">入仓性质：</td>
		<td class="form_input">
			<select id="in_type" name="in_type">
				<option value="">请选择</option>
				<option value="1">产品入库</option>
				<option value="2">材料入库</option>
				<option value="3">自制半成品入库</option>
				<option value="4">采购单入库</option>
			</select>
		</td>
		<td class="form_title">入库日期：</td>
		<td class="form_input"><input type="text" id="in_date" name="in_date" value="" class="Wdate" onFocus="WdatePicker({isShowWeek:true})" /></td>
	</tr>
	<tr>
		<td class="form_title">仓库代码：</td>
		<td class="form_input">
		<select id="depot_code" name="depot_code">
				<option value="" >请选择</option>
				 <c:forEach items="${deportList}" var="d" varStatus="status">
					<option value="${d.depot_code}">${d.depot_code}[${d.depot_nane}]</option>
				</c:forEach>
		</select>
		</td>
		<td class="form_title">财务统计核算期：</td>
		<td class="form_input"><input type="hidden" id="acc_period" name="acc_period" value="" /><div id="acc_period_panel"></div></td>
	
		<td class="form_title">入仓部门代码：</td>
		<td class="form_input">
		<select id="dep_codedep_code" name="dep_code">
				<option value="" >请选择</option>
				 <c:forEach items="${departList}" var="d" varStatus="status">
					<option value="${d.dep_code}">${d.dep_code}[${d.dep_name}]</option>
				</c:forEach>
		</select>
		${dep_code} </td>
	</tr>
	<tr>
		<td class="form_title">所属采购单号：</td>
		<td class="form_input"><input type="text" id="pur_order_code" readonly name="pur_order_code" value="${in_warehouse_code}" /></td>
	
		<td class="form_title">生产批次：</td>
		<td class="form_input"><input type="text" id="seq_id" name="seq_id" value="" /></td>
		<td class="form_title">供应商代码：</td>
		<td class="form_input"><input type="text" id="supplier" name="supplier" value="" /></td>
	</tr>
	<tr>
	  <td class="form_title">备注：</td>
	  <td class="form_input" colspan="5"><input type="text" id="remark" name="remark" value="" /></td>
	</tr>
	<tr>
	  <td class="form_title">入仓产品</td>
	  <td class="form_input" colspan="5"><table width="340" border="0"
						cellpadding="2" cellspacing="1" class="listLogo" id="MGoodsPanel">
						<tr>
							<td>产品代码</td>
							<td>产品名称</td>
							<td>入仓数量</td>
							<td>重量</td>
							<td>计量单位</td>
								<td><input type="button" name="button" id="button"
									value="增加产品" onClick="selectGoods()">
								</td>
						</tr>
					</table></td>
    </tr>
</table>
</form>
</body>
</html>
